/**
 * FileName: WechatIndexController
 * Author:   Leopold
 * Date:     2018/9/4 11:16
 * Description: 微信入口
 * History:
 */
package cn.mcsys.platform.core.web;

import cn.mcsys.myadmin.common.web.JsonResult;
import cn.mcsys.myadmin.dubbo.service.BackService;
import cn.mcsys.myadmin.modules.air.entity.AirCar;
import cn.mcsys.myadmin.modules.air.entity.AirWorker;
import cn.mcsys.myadmin.modules.viewer.entity.AirTickets;
import cn.mcsys.platform.core.service.PlatformService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class IndexController {

    private static Logger logger = LoggerFactory.getLogger(IndexController.class);

    @Autowired
    private BackService backService;

    @Autowired
    private PlatformService platformService;

    @RequestMapping("echartData")
    @ResponseBody
    public JsonResult echartData(Model model) {
        return JsonResult.success();
    }

    @RequestMapping("index")
    public String index(Model model) {
        System.out.println("go to index!getting data");
        Map<String, Object> result = new HashMap<>();
        result.put("airRidePointDtoList",platformService.getRidePointDtoList2());
        model.addAttribute("dataMap", result);
        return "airDispatch";
    }


    @GetMapping("getSpecialGps")
    @ResponseBody
    public JsonResult getSpecialGps() {
        System.out.println("getSpecialGps....");
        return JsonResult.success(backService.getAllPointsCar());
    }

    @GetMapping("getRidePointDtoList")
    @ResponseBody
    public JsonResult getRidePointDtoList() {
        return JsonResult.success(platformService.getRidePointDtoList2());
    }

    @GetMapping("getTicketSum")
    @ResponseBody
    public JsonResult getTicketSum() {
        Map<String, Integer> result = new HashMap<>();

        List<AirTickets> allTicketsToday = backService.getAllTicketsToday();
        Integer a = 0;
        if(allTicketsToday!=null) {
            a = allTicketsToday.size();
        }

        result.put("appointSum", a);
        result.put("checkedSum", 0);
        return JsonResult.success(result);
    }

    @GetMapping("getCarDetailByCarNumber")
    @ResponseBody
    public JsonResult getDetailByCarNumber(String carNumber) {
        AirCar car = backService.getCarDetailByCarNumber(carNumber);
        return JsonResult.success(car);
    }

    @GetMapping("getRidePointDetailById")
    @ResponseBody
    public JsonResult getRidePointDetailByName(Integer id) {
        Map<String, Object> result = new HashMap<>();
        List<AirCar> carList = backService.selectByPointId(id);
        List<AirWorker> airWorkerList = backService.getWorkersByRidePointId(id);
        result.put("airRidePoint", backService.selectPointById(id));
        result.put("carList", carList);
        result.put("workerList", airWorkerList);
        return JsonResult.success(result);
    }

    @GetMapping("getCarDetailByCarId")
    @ResponseBody
    public JsonResult getCarDetailByCarId(Integer id) {
        AirCar car = backService.getCarDetailByCarId(id);

        return JsonResult.success(car);
    }

    @GetMapping("getMessageLeast")
    @ResponseBody
    public JsonResult getMessageLeast() {
//        String date = DateUtils.getDate("yyyy-MM-dd");
//        List<AirRealtimeMessage> submission = backService.getSubmission(date);
//        return JsonResult.success(submission);
        return JsonResult.success(backService.getMessageLeast());
    }

    @GetMapping("getMoveChartData")
    @ResponseBody
    public JsonResult getMoveChartData() {
        return JsonResult.success(platformService.getMoveChartData());
    }

}
